<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<button id="btn" style="display: none">click</button>

<script>
    let i = 1
    const btn = document.getElementById('btn')

    btn.onclick = function () {
        console.log('你点击了按钮' + i++)
    }

    const clickEvent = new Event('click')

    setTimeout(() => {
        btn.dispatchEvent(clickEvent)
    }, 2000)
    setTimeout(() => {
        btn.click()
    }, 3000)
</script>
</body>
</html>
